﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Misc
{
    class Helper
    {
        public static bool AreUniqueChars(string input)
        { 
            int sum = 0;
            foreach (char c in input)
            {
                sum = sum ^ (int)c;
                if(sum == 0)
                    return false;
            }
            return true;
        }

        public static char[] removeDuplicates(char[] str) 
        {
             if (str == null) return str;
             int len = str.Length;
             if (len < 2) return str;

             int tail = 1;

             for (int i = 1; i < len; ++i) 
             {
                 int j;
                 for (j = 0; j < tail; ++j) 
                 {
                    if (str[i] == str[j]) break;
                 }
                 if (j == tail) 
                 {
                    str[tail] = str[i];
                    ++tail;
                 }
             }
             for (int i = tail; i < str.Length; i++ )
                 str[i] = '\0';
            return str;
        }

        public static void FindFirstOne()
        {
            int[] a = { 1, 1, 1, 1, 1, 1, 1, 1 };
            Console.WriteLine(FindFirstOneEx(a, 0, a.Length - 1));            
        }
        private static int FindFirstOneEx(int[] a, int start, int end)
        {
            if (start == end)
                return start;

            int mid = (start + end) / 2;

            if (a[mid] == 1)
                return FindFirstOneEx(a, start, mid);

            else if (a[end] == 1)
                return FindFirstOneEx(a, mid + 1, end);

            else
                return -1;
        }
    }
}
